BOOST_ROOT=..\boost_1_44_0
BOOST_INCLUDE_DIR=$(BOOST_ROOT)
BOOST_LIB_DIR=$(BOOST_ROOT)\lib
SDL_ROOT=..\SDL-1.2.14
SDL_INCLUDE_DIR=$(SDL_ROOT)\include
SDL_SOLUTION_DIR=$(SDL_ROOT)\VisualC
SDL_PROJECT_DIR=$(SDL_SOLUTION_DIR)\SDL
SDL_MAIN_PROJECT_DIR=$(SDL_SOLUTION_DIR)\SDLmain
SDL_STATIC_LIB_DIR=$(SDL_PROJECT_DIR)\ReleaseStaticRuntime
SDL_MAIN_STATIC_LIB_DIR=$(SDL_MAIN_PROJECT_DIR)\Release_NOSTDIOStaticRuntime
SDL_MAIN_STATIC_DEBUG_LIB_DIR=$(SDL_MAIN_PROJECT_DIR)\ReleaseStaticRuntime
SDL_LIB_DIR=$(SDL_PROJECT_DIR)\Release
SDL_MAIN_LIB_DIR=$(SDL_MAIN_PROJECT_DIR)\Release_NOSTDIO
SDL_MAIN_DEBUG_LIB_DIR=$(SDL_MAIN_PROJECT_DIR)\Release
SDL_STATIC_BIN_DIR=$(SDL_PROJECT_DIR)\ReleaseStaticRuntime
SDL_BIN_DIR=$(SDL_PROJECT_DIR)\Release
INCLUDE_DIR=include
SDL_CONFIG_HEADER=$(INCLUDE_DIR)\SDL_config_win32.h
LIBRARIES=kernel32.lib \
  user32.lib \
  gdi32.lib \
  winspool.lib \
  comdlg32.lib \
  advapi32.lib \
  shell32.lib \
  ole32.lib \
  oleaut32.lib \
  uuid.lib \
  odbc32.lib \
  odbccp32.lib \
  strmiids.lib
BOOST_STATIC_LIBRARIES=libboost_date_time-vc90-mt-s.lib \
  libboost_thread-vc90-mt-s.lib
BOOST_LIBRARIES=libboost_date_time-vc90-mt.lib \
  libboost_thread-vc90-mt.lib
SDL_LIBRARIES=SDL.lib \
	SDLmain.lib
CPP_EXT=cpp
OBJECT_EXT=obj
EXECUTABLE_EXT=exe
DLL_EXT=dll
LIB_EXT=lib
SOLUTION_EXT=sln
BJAM=$(BOOST_ROOT)\bjam.$(EXECUTABLE_EXT)
SDL_DLL=SDL.$(DLL_EXT)
SOURCE_DIR=src
VIDEO_CAPTURE_SOURCE_DIR=$(SOURCE_DIR)\videocapture
VIDEO_CAPTURE_WINDOWS_SOURCE_DIR=$(VIDEO_CAPTURE_SOURCE_DIR)\windows
SDL_SOURCE_DIR=$(SOURCE_DIR)\sdl
TEST_SOURCE_DIR=$(SOURCE_DIR)\test
OBJECT_DIR=build
STATIC_OBJECT_DIR=build\static
TEST_OBJECT_FILE=$(STATIC_OBJECT_DIR)\Test.$(OBJECT_EXT)
STATIC_TARGET_DIR=bin\static
TARGET_DIR=bin
STATIC_LIB_DIR=lib\static
LIB_DIR=lib
TEST_TARGET=$(STATIC_TARGET_DIR)\Test.$(EXECUTABLE_EXT)
VIDEO_CAPTURE_STATIC_TARGET=$(STATIC_LIB_DIR)\libvideocapture_static.$(LIB_EXT)
VIDEO_CAPTURE_TARGET=$(LIB_DIR)\libvideocapture.$(LIB_EXT)
SDL_STATIC_TARGET=$(STATIC_LIB_DIR)\libsdlmanager_static.$(LIB_EXT)
SDL_TARGET=$(LIB_DIR)\libsdlmanager.$(LIB_EXT)
COMPILER=cl
COMPILER_OPTIONS_STATIC_DEBUG=/nologo /c /EHsc /MT /DDEBUG
COMPILER_OPTIONS_DEBUG=/nologo /c /EHsc /MD /DDEBUG
COMPILER_OPTIONS_STATIC=/nologo /c /EHsc /MT
COMPILER_OPTIONS=/nologo /c /EHsc /MD
LINKER=link
LINKER_OPTIONS_WINDOWS=/nologo /SUBSYSTEM:WINDOWS
LINKER_OPTIONS=/nologo
LIBRARY_TOOL=lib
LIBRARY_TOOL_OPTIONS_WINDOWS=/nologo /SUBSYSTEM:WINDOWS
LIBRARY_TOOL_OPTIONS=/nologo
VCBUILD=vcbuild
VCBUILD_OPTIONS=
VCBUILD_OPTIONS_CLEAN=/clean
SDL_SOLUTION_FILE=$(SDL_SOLUTION_DIR)\SDL.$(SOLUTION_EXT)
SDL_STATIC_DEBUG_CONFIGURATION="ReleaseStaticRuntime|Win32"
SDL_STATIC_CONFIGURATION="Release_NoSTDIOStaticRuntime|Win32"
SDL_DEBUG_CONFIGURATION="Release|Win32"
SDL_CONFIGURATION="Release_NoSTDIO|Win32"
RMDIR=rmdir /s
MKDIR=mkdir
COPY=copy /y
IF_EXIST=if exist
IF_NOT_EXIST=if not exist
LIST_OBJECT_FILES=ListObjectFiles.bat
OBJECT_FILE_LIST=ObjectFilesList.txt
VIDEO_CAPTURE_OBJECT_FILE_LIST=VideoCaptureObjectFiles.txt
VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST=VideoCaptureWindowsObjectFiles.txt
SDL_OBJECT_FILE_LIST=SDLObjectFiles.txt
STATIC_OBJECT_FILE_LIST=StaticObjectFilesList.txt
STATIC_VIDEO_CAPTURE_OBJECT_FILE_LIST=StaticVideoCaptureObjectFiles.txt
STATIC_VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST=StaticVideoCaptureWindowsObjectFiles.txt
STATIC_SDL_OBJECT_FILE_LIST=StaticSDLObjectFiles.txt
BUILD_BOOST=BuildBoost.bat
BUILD_BJAM=BuildBjam.bat

# Common source files when compiling against the dynamic c runtime
!IF [$(LIST_OBJECT_FILES) $(OBJECT_FILE_LIST) $(SOURCE_DIR) $(OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) OBJECT_FILES]
!INCLUDE $(OBJECT_FILE_LIST)
!ENDIF

# Video capture source files when compiling against the dynamic c runtime
!IF [$(LIST_OBJECT_FILES) $(VIDEO_CAPTURE_OBJECT_FILE_LIST) $(VIDEO_CAPTURE_SOURCE_DIR) $(OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) VIDEO_CAPTURE_OBJECT_FILES]
!INCLUDE $(VIDEO_CAPTURE_OBJECT_FILE_LIST)
!ENDIF

# Windows video capture source files when compiling against the dynamic c runtime
!IF [$(LIST_OBJECT_FILES) $(VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST) $(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR) $(OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) VIDEO_CAPTURE_WINDOWS_OBJECT_FILES]
!INCLUDE $(VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST)
!ENDIF

# SDL manager source files when compiling against the dynamic c runtime
!IF [$(LIST_OBJECT_FILES) $(SDL_OBJECT_FILE_LIST) $(SDL_SOURCE_DIR) $(OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) SDL_OBJECT_FILES]
!INCLUDE $(SDL_OBJECT_FILE_LIST)
!ENDIF

# Common source files when compiling against the static c runtime
!IF [$(LIST_OBJECT_FILES) $(STATIC_OBJECT_FILE_LIST) $(SOURCE_DIR) $(STATIC_OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) STATIC_OBJECT_FILES]
!INCLUDE $(STATIC_OBJECT_FILE_LIST)
!ENDIF

# Video capture source files when compiling against the static c runtime
!IF [$(LIST_OBJECT_FILES) $(STATIC_VIDEO_CAPTURE_OBJECT_FILE_LIST) $(VIDEO_CAPTURE_SOURCE_DIR) $(STATIC_OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) STATIC_VIDEO_CAPTURE_OBJECT_FILES]
!INCLUDE $(STATIC_VIDEO_CAPTURE_OBJECT_FILE_LIST)
!ENDIF

# Windows video capture source files when compiling against the static c runtime
!IF [$(LIST_OBJECT_FILES) $(STATIC_VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST) $(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR) $(STATIC_OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) STATIC_VIDEO_CAPTURE_WINDOWS_OBJECT_FILES]
!INCLUDE $(STATIC_VIDEO_CAPTURE_WINDOWS_OBJECT_FILE_LIST)
!ENDIF

# SDL manager source files when compiling against the static c runtime
!IF [$(LIST_OBJECT_FILES) $(STATIC_SDL_OBJECT_FILE_LIST) $(SDL_SOURCE_DIR) $(STATIC_OBJECT_DIR) $(CPP_EXT) $(OBJECT_EXT) STATIC_SDL_OBJECT_FILES]
!INCLUDE $(STATIC_SDL_OBJECT_FILE_LIST)
!ENDIF

# Build common source files against the dynamic c runtime
{$(SOURCE_DIR)}.$(CPP_EXT){$(OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(OBJECT_DIR) $(MKDIR) $(OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS) /I$(BOOST_INCLUDE_DIR) /Fo$(OBJECT_DIR)\ $<

# Build video capture source files against the dynamic c runtime
{$(VIDEO_CAPTURE_SOURCE_DIR)}.$(CPP_EXT){$(OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(OBJECT_DIR) $(MKDIR) $(OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /Fo$(OBJECT_DIR)\ $<

# Build windows video capture source files against the dynamic c runtime
{$(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR)}.$(CPP_EXT){$(OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(OBJECT_DIR) $(MKDIR) $(OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /Fo$(OBJECT_DIR)\ $<

# Build sdl manager source files against the dynamic c runtime
{$(SDL_SOURCE_DIR)}.$(CPP_EXT){$(OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(OBJECT_DIR) $(MKDIR) $(OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /I$(SDL_INCLUDE_DIR) /Fo$(OBJECT_DIR)\ $<

# Build common source files against the static c runtime
{$(SOURCE_DIR)}.$(CPP_EXT){$(STATIC_OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(STATIC_OBJECT_DIR) $(MKDIR) $(STATIC_OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS_STATIC) /I$(BOOST_INCLUDE_DIR) /Fo$(STATIC_OBJECT_DIR)\ $<

# Build video capture source files against the static c runtime
{$(VIDEO_CAPTURE_SOURCE_DIR)}.$(CPP_EXT){$(STATIC_OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(STATIC_OBJECT_DIR) $(MKDIR) $(STATIC_OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS_STATIC) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /Fo$(STATIC_OBJECT_DIR)\ $<

# Build windows video capture source files against the static c runtime
{$(VIDEO_CAPTURE_WINDOWS_SOURCE_DIR)}.$(CPP_EXT){$(STATIC_OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(STATIC_OBJECT_DIR) $(MKDIR) $(STATIC_OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS_STATIC) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /Fo$(STATIC_OBJECT_DIR)\ $<

# Build sdl manager source files against the static c runtime
{$(SDL_SOURCE_DIR)}.$(CPP_EXT){$(STATIC_OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(STATIC_OBJECT_DIR) $(MKDIR) $(STATIC_OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS_STATIC) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /I$(SDL_INCLUDE_DIR) /Fo$(STATIC_OBJECT_DIR)\ $<

# Build test application source files against the static c runtime
{$(TEST_SOURCE_DIR)}.$(CPP_EXT){$(STATIC_OBJECT_DIR)}.$(OBJECT_EXT):
	$(IF_NOT_EXIST) $(STATIC_OBJECT_DIR) $(MKDIR) $(STATIC_OBJECT_DIR)
  $(COMPILER) $(COMPILER_OPTIONS_STATIC) /I$(SOURCE_DIR) /I$(VIDEO_CAPTURE_SOURCE_DIR) /I$(SDL_SOURCE_DIR) /I$(BOOST_INCLUDE_DIR) /I$(SDL_INCLUDE_DIR) /Fo$(STATIC_OBJECT_DIR)\ $<


# Build video capture library against the dynamic c runtime
$(VIDEO_CAPTURE_TARGET):$(OBJECT_FILES) $(VIDEO_CAPTURE_OBJECT_FILES) $(VIDEO_CAPTURE_WINDOWS_OBJECT_FILES)
	$(IF_NOT_EXIST) $(LIB_DIR) $(MKDIR) $(LIB_DIR)
	$(LIBRARY_TOOL) $(LIBRARY_TOOL_OPTIONS) /out:$@ $**

# Build video capture library against the static c runtime
$(VIDEO_CAPTURE_STATIC_TARGET):$(STATIC_OBJECT_FILES) $(STATIC_VIDEO_CAPTURE_OBJECT_FILES) $(STATIC_VIDEO_CAPTURE_WINDOWS_OBJECT_FILES)
	$(IF_NOT_EXIST) $(STATIC_LIB_DIR) $(MKDIR) $(STATIC_LIB_DIR)
	$(LIBRARY_TOOL) $(LIBRARY_TOOL_OPTIONS) /out:$@ $**

# Build sdl manager library against the dynamic c runtime
$(SDL_TARGET):$(SDL_OBJECT_FILES)
	$(IF_NOT_EXIST) $(LIB_DIR) $(MKDIR) $(LIB_DIR)
	$(LIBRARY_TOOL) $(LIBRARY_TOOL_OPTIONS_WINDOWS) /out:$@ $**

# Build sdl manager library against the static c runtime
$(SDL_STATIC_TARGET):$(STATIC_SDL_OBJECT_FILES)
	$(IF_NOT_EXIST) $(STATIC_LIB_DIR) $(MKDIR) $(STATIC_LIB_DIR)
	$(LIBRARY_TOOL) $(LIBRARY_TOOL_OPTIONS_WINDOWS) /out:$@ $**

# Build the test application against the static c runtime
$(TEST_TARGET):$(TEST_OBJECT_FILE) $(VIDEO_CAPTURE_STATIC_TARGET) $(SDL_STATIC_TARGET)
	$(IF_NOT_EXIST) $(STATIC_TARGET_DIR) $(MKDIR) $(STATIC_TARGET_DIR)
  $(LINKER) $(LINKER_OPTIONS_WINDOWS) /out:$@ $(LIBRARIES) /LIBPATH:$(BOOST_LIB_DIR) $(BOOST_STATIC_LIBRARIES) /LIBPATH:$(SDL_STATIC_LIB_DIR) /LIBPATH:$(SDL_MAIN_STATIC_LIB_DIR) $(SDL_LIBRARIES) $**
	$(COPY) $(SDL_STATIC_BIN_DIR)\$(SDL_DLL) $(STATIC_TARGET_DIR)\$(SDL_DLL)

# Build libvideocapture.lib against the dynamic c runtime
videocapture:$(VIDEO_CAPTURE_TARGET)

# Build libvideocapture_static.lib against the static c runtime
videocapture_static:$(VIDEO_CAPTURE_STATIC_TARGET)

# Build libsdlmanager.lib against the dynamic c runtime
sdlmanager:$(SDL_TARGET)

# Build libsdlmanager_static.lib against the static c runtime
sdlmanager_static:$(SDL_STATIC_TARGET)

# Build the test application
test:sdl_static
test:boost
test:$(TEST_TARGET)

clean:
	$(IF_EXIST) $(TARGET_DIR) $(RMDIR) $(TARGET_DIR)
	$(IF_EXIST) $(OBJECT_DIR) $(RMDIR) $(OBJECT_DIR)
	$(IF_EXIST) $(LIB_DIR) $(RMDIR) $(LIB_DIR)

$(BJAM):
	$(BUILD_BJAM) $(BOOST_ROOT)

bjam:$(BJAM)

boost:bjam
  $(BUILD_BOOST) $(BOOST_ROOT)

sdl:
	$(COPY) $(SDL_CONFIG_HEADER) $(SDL_INCLUDE_DIR)
	$(VCBUILD) $(VCBUILD_OPTIONS) $(SDL_SOLUTION_FILE) $(SDL_CONFIGURATION)

sdl_debug:
	$(COPY) $(SDL_CONFIG_HEADER) $(SDL_INCLUDE_DIR)
	$(VCBUILD) $(VCBUILD_OPTIONS) $(SDL_SOLUTION_FILE) $(SDL_DEBUG_CONFIGURATION)

sdl_static:
	$(COPY) $(SDL_CONFIG_HEADER) $(SDL_INCLUDE_DIR)
	$(VCBUILD) $(VCBUILD_OPTIONS) $(SDL_SOLUTION_FILE) $(SDL_STATIC_CONFIGURATION)

sdl_static_debug:
	$(COPY) $(SDL_CONFIG_HEADER) $(SDL_INCLUDE_DIR)
	$(VCBUILD) $(VCBUILD_OPTIONS) $(SDL_SOLUTION_FILE) $(SDL_STATIC_DEBUG_CONFIGURATION)

sdl_clean:
	$(VCBUILD) $(VCBUILD_OPTIONS_CLEAN) $(SDL_SOLUTION_FILE) $$ALL